//
//  ZWLDetailViewController.m
//  ZWLMusic
//
//  Created by dllo on 16/1/6.
//  Copyright © 2016年 ZKJ. All rights reserved.
//

#import "ZWLDetailViewController.h"

@interface ZWLDetailViewController ()<UITableViewDataSource,UITableViewDelegate>
@property (nonatomic,strong)UITableView *tableView;
@end

@implementation ZWLDetailViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    [self getDataWork];
    [self.view addSubview:self.tableView];
    
}

#pragma mark NetWork
- (void)getDataWork {
    [ZKJNetWorkTool getWithUrl:self.url parameter:nil httpHeader:nil responseType:ResponseTypeJSON success:^(id result) {
        NSArray *array = result[@"singers"];
        NSMutableArray *arr = [[NSMutableArray alloc]initWithCapacity:0];
        for (NSDictionary *dic in array) {
            ZWLSigerModel *singerModel = [[ZWLSigerModel alloc]initWithDictionary:dic];
            [arr addObject:singerModel];
        }
        self.dataSource = [[NSArray alloc]initWithArray:arr];
        [self.tableView reloadData];
    } fail:^(NSError *error) {
        NSLog(@"请求失败");
    }];
}

- (UITableView *)tableView {
    if (!_tableView) {
        self.tableView = [[UITableView alloc]initWithFrame:self.view.bounds style:UITableViewStyleGrouped];
    }
    _tableView.delegate = self;
    _tableView.dataSource = self;
    [_tableView registerClass:[ZWLSingerTableViewCell class] forCellReuseIdentifier:@"ZWLSingerTableViewCellIdentifier"];
    return _tableView;
}
#pragma mark UITableViewDelegate

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return self.dataSource.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    ZWLSingerTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"ZWLSingerTableViewCellIdentifier"];
    ZWLSigerModel *singerModel = self.dataSource[indexPath.row];
    cell.singerModel = singerModel;
    return cell;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    return ptsHEIGTH * 100;
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
